package com.ruoyi.web.controller.productManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StoreRawMaterialsSummary;
import com.ruoyi.system.service.IStoreRawMaterialsSummaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门店原料 Controller
 *
 * @author ruoyi
 * @date 2025-05-27
 */
@Api(tags="门店原料")
@RestController
@RequestMapping("/system/storeRawMaterialsSummary")
public class StoreRawMaterialsSummaryController extends BaseController
{
    @Autowired
    private IStoreRawMaterialsSummaryService storeRawMaterialsSummaryService;

    /**
     * 通过门店名称查询门店原料列表
     */
    @ApiOperation("通过门店名称查询门店原料列表")
    @PreAuthorize("@ss.hasPermi('system:summary:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String storeName)
    {
        startPage();
        List<StoreRawMaterialsSummary> list = storeRawMaterialsSummaryService.selectStoreRawMaterialsSummaryListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出门店原料列表
     */
    @ApiOperation("导出门店原料列表")
    @PreAuthorize("@ss.hasPermi('system:summary:export')")
    @Log(title = "门店原料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String storeName)
    {
        List<StoreRawMaterialsSummary> list = storeRawMaterialsSummaryService.selectStoreRawMaterialsSummaryListByName(storeName);
        ExcelUtil<StoreRawMaterialsSummary> util = new ExcelUtil<StoreRawMaterialsSummary>(StoreRawMaterialsSummary.class);
        util.exportExcel(response, list, "门店原料数据");
    }

    /**
     * 通过id获取门店原料详细信息
     */
    @ApiOperation("通过id获取门店原料详细信息")
    @PreAuthorize("@ss.hasPermi('system:summary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storeRawMaterialsSummaryService.selectStoreRawMaterialsSummaryById(id));
    }

    /**
     * 新增门店原料
     */
    @ApiOperation("新增门店原料")
    @PreAuthorize("@ss.hasPermi('system:summary:add')")
    @Log(title = "门店原料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreRawMaterialsSummary storeRawMaterialsSummary)
    {
        return toAjax(storeRawMaterialsSummaryService.insertStoreRawMaterialsSummary(storeRawMaterialsSummary));
    }

    /**
     * 修改门店原料
     */
    @ApiOperation("修改门店原料")
    @PreAuthorize("@ss.hasPermi('system:summary:edit')")
    @Log(title = "门店原料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreRawMaterialsSummary storeRawMaterialsSummary)
    {
        return toAjax(storeRawMaterialsSummaryService.updateStoreRawMaterialsSummary(storeRawMaterialsSummary));
    }

    /**
     * 通过id批量删除门店原料信息
     */
    @ApiOperation("通过id批量删除门店原料信息")
    @PreAuthorize("@ss.hasPermi('system:summary:remove')")
    @Log(title = "门店原料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeRawMaterialsSummaryService.deleteStoreRawMaterialsSummaryByIds(ids));
    }
}
